<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
    <title>用户添加收货地址页面</title>
</head>
<?php 
include_once("inc.php");
include_once("base.php");
$tb_name = "address";
$rs = array();
if ($_REQUEST["id"]) {
	$rs = db_get_row("select * from $tb_name where id=". $_REQUEST["id"]);
}
if ($_POST){
	$data = array();
	$data["title"] = "'".$_POST["title"]."'";
	$data["userid"] = "'".$_SESSION["id"]."'";
	$data["sex"] = "'".$_POST["sex"]."'";
	$data["nickname"] = "'".$_POST["nickname"]."'";
	$data["tel"] = "'".$_POST["tel"]."'";
	if ($_REQUEST["id"]) {
		db_mdf($tb_name,$data,$_REQUEST["id"]);
	} else {
		db_add($tb_name,$data);
	}
	urlMsg("提交成功", $tb_name."_list.php");
	die;
}	
?>
<script>
function check()
{
	if(document.form1.nickname.value==""){
		alert("姓名为必填");
		document.form1.nickname.focus();
		return false;}
	
	var str1=document.form1.nickname.value; 
 	var reg1 = /^[\u4e00-\u9fa5]{2,15}$/i; 
	 if (!reg1.test(str1)) 
	 {
	  alert("请输入2-8个汉字！"); 
	  document.form1.nickname.focus();
	  return false;
	  }
	var mobile=document.form1.tel.value;
		if(mobile.length==0) 
       { 
          alert('请输入手机号码！'); 
          document.form1.tel.focus(); 
          return false; 
       }     
       if(mobile.length!=11) 
       { 
           alert('请输入有效的手机号码！'); 
           document.form1.tel.focus(); 
           return false; 
       }
       var myreg = /^(((13[0-9]{1})|(14[0-9]{1})|(15[0-9]{1})|(17[0-9]{1})|(18[0-9]{1}))+\d{8})$/; 
       if(!myreg.test(mobile)) 
       { 
           alert('请输入有效的手机号码！'); 
           document.form1.tel.focus(); 
           return false; 
       }
		if(document.form1.address.value==""){
		alert("地址为必填");
		document.form1.address.focus();
		return false;}
}
</script>
<body>
	<table width="100%" border="0" cellpadding="0" cellspacing="0">
		<tr>
			<td width="17" rowspan="2" valign="top" bgcolor="#FFFFFF"></td>
			<td valign="top">
				<table width="100%" height="31" border="0" cellpadding="0" cellspacing="0">
					<tr bgcolor="#FFFFFF">
						<td height="31">
							<div class="title">添加/修改信息</div>
						</td>
					</tr>
				</table>
			</td>
			<td width="16" rowspan="2" bgcolor="#FFFFFF"></td>
		</tr>
		<tr>
			<td valign="top" bgcolor="#F7F8F9">
				<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
					<tr><td colspan="4" height="10"></td></tr>
					<tr>
						<td width="1%">&nbsp;</td>
						<td width="96%">
							<table width="100%">
								<tr>
									<td colspan="2">
										<form name="form1" method="post" action="?" onSubmit="return check()"  enctype="multipart/form-data">
											<input type="hidden" name="id" value="<?php echo $rs["id"];?>" />
											<input type="hidden" name="title1" value="<?php echo $rs["title"];?>" />
											<table width="100%" class="cont">
												<tr>
													<td width="" align="right"> 姓名：</td>
													<td width="">
														<input class="text" name="nickname" type="text" maxlength="18" value="<?php echo $rs["nickname"];?>">
													</td>
												</tr>
												<tr>
													<td width="" align="right">
														<span class="red">*</span> 性别：
													</td>
													<td width="">
														<select name="sex">
															<option value="男" <?php if($rs["sex"]=="男"){echo "selected";}?>>男</option>
															<option value="女" <?php if($rs["sex"]=="女"){echo "selected";}?>>女</option>
														</select>
													</td>
												</tr>
												<tr>
													<td width="" align="right">
														<span class="red">*</span> 电话：
													</td>
													<td width="">
														<input class="text" name="tel" type="text" maxlength="18" value="<?php echo $rs["tel"];?>">
													</td>
												</tr>
												<tr>
													<td width="120" align="right">
														<span class="red">*</span>地址：
													</td>
													<td>
														<input name="title" type="text" class="text" size="30" style="width: 350px;" value="<?php echo $rs["title"];?>">
													</td>
												</tr>
												<tr>
													<td align="right"></td>
													<td>
														<input class="btn" type="submit" value="提交" id="submitBtn" />
														<input name="button" type="button" class="btn" onClick="javascript:history.back();" value="返回">
													</td>
												</tr>
											</table>
										</form>
									</td>
								</tr>
							</table>
						</td>
						<td width="1%">&nbsp;</td>
					</tr>
					<tr><td height="20"></td></tr>
				</table>
			</td>
		</tr>
	</table>
</body>
</html>